package com.youbug.mall.ware_wms.service.impl;

import com.youbug.mall.ware_wms.entity.WmsWareOrderTask;
import com.youbug.mall.ware_wms.mapper.WmsWareOrderTaskMapper;
import com.youbug.mall.ware_wms.service.IWmsWareOrderTaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.youbug.mall.ware_wms.entity.WmsWareOrderTask;
import org.springframework.util.ObjectUtils;
import com.youbug.common.vo.QueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.StringUtils;
import org.springframework.util.ObjectUtils;

/**
 * <p>
 * 库存工作单 服务实现类
 * </p>
 *
 * @author youbug
 * @since 2024-07-14
 */
@Service
public class WmsWareOrderTaskServiceImpl extends ServiceImpl<WmsWareOrderTaskMapper, WmsWareOrderTask> implements IWmsWareOrderTaskService {

        @Override
        public IPage<WmsWareOrderTask> getWmsWareOrderTaskPage(QueryVo<WmsWareOrderTask> queryVo) {

        Page<WmsWareOrderTask> paramPage = new Page<>();

        paramPage.setCurrent(queryVo.getCurrentPage());

        paramPage.setSize(queryVo.getPageSize());

        QueryWrapper<WmsWareOrderTask> wrapper = new QueryWrapper<>();

        WmsWareOrderTask wmsWareOrderTask = queryVo.getPayload();

        if(!ObjectUtils.isEmpty(wmsWareOrderTask)){
                    if(wmsWareOrderTask.getId()!=null){
                    wrapper.gt("id", wmsWareOrderTask.getId());
                    }
                    if(wmsWareOrderTask.getOrderId()!=null){
                    wrapper.gt("order_id", wmsWareOrderTask.getOrderId());
                    }
            if(StringUtils.hasText(wmsWareOrderTask.getOrderSn())){
                wrapper.eq("order_sn", wmsWareOrderTask.getOrderSn());
            }
            if(StringUtils.hasText(wmsWareOrderTask.getConsignee())){
                wrapper.eq("consignee", wmsWareOrderTask.getConsignee());
            }
            if(StringUtils.hasText(wmsWareOrderTask.getConsigneeTel())){
                wrapper.eq("consignee_tel", wmsWareOrderTask.getConsigneeTel());
            }
            if(StringUtils.hasText(wmsWareOrderTask.getDeliveryAddress())){
                wrapper.eq("delivery_address", wmsWareOrderTask.getDeliveryAddress());
            }
            if(StringUtils.hasText(wmsWareOrderTask.getOrderComment())){
                wrapper.eq("order_comment", wmsWareOrderTask.getOrderComment());
            }
                    if(wmsWareOrderTask.getTaskStatus()!=null){
                    wrapper.gt("task_status", wmsWareOrderTask.getTaskStatus());
                    }
            if(StringUtils.hasText(wmsWareOrderTask.getOrderBody())){
                wrapper.eq("order_body", wmsWareOrderTask.getOrderBody());
            }
            if(StringUtils.hasText(wmsWareOrderTask.getTrackingNo())){
                wrapper.eq("tracking_no", wmsWareOrderTask.getTrackingNo());
            }
                    if(wmsWareOrderTask.getWareId()!=null){
                    wrapper.gt("ware_id", wmsWareOrderTask.getWareId());
                    }
            if(StringUtils.hasText(wmsWareOrderTask.getTaskComment())){
                wrapper.eq("task_comment", wmsWareOrderTask.getTaskComment());
            }
        }
        if(!ObjectUtils.isEmpty(queryVo.getStartTime())){
            wrapper.gt("create_time", queryVo.getStartTime());
        }
        if(!ObjectUtils.isEmpty(queryVo.getEndTime())){
            wrapper.lt("create_time", queryVo.getEndTime());
        }
        wrapper.orderByDesc("create_time");

        Page<WmsWareOrderTask> page = this.page(paramPage, wrapper);

        return page;
        }

    @Override
    public WmsWareOrderTask getOrderTaskByOrderSn(String orderSn) {
        WmsWareOrderTask orderTask = this.getOne(new QueryWrapper<WmsWareOrderTask>().eq("order_sn", orderSn));

        return orderTask;
    }

       /* @Transactional(transactionManager = "transactionManagerXXX", rollbackFor = Exception.class)
        public boolean saveBatch(Collection<WmsWareOrderTask> entityList) {
        return saveBatch(entityList, DEFAULT_BATCH_SIZE);
        }
        */
}
